package com.poc.party.service.wiredrule;

import com.meta.common.ConstDef;
import com.meta.nd.service.DefaultWiredServiceImpl;
import com.meta.nd.service.WiredService;
import com.meta.nd.vo.Nv;
import com.meta.rule.RuleRunContext;

public class PartyWiredRuleImpl2 implements WiredService {
    WiredService saveWiredService = new PartySaveWiredRuleImpl();
    WiredService commitWiredService = new PartyCommitWiredRuleImpl();
    WiredService defaultWiredService = new DefaultWiredServiceImpl();
    private WiredService getWiredService(String transactionType){
        if (transactionType.equals(ConstDef.TRANSACTION_TYPE_SAVE))
            return saveWiredService;
        else if (transactionType.equals(ConstDef.TRANSACTION_TYPE_COMMIT))
            return commitWiredService;
        else
            return defaultWiredService;
    }
    @Override
    public void doPreWiredMethod(String transactionType, Nv nv, RuleRunContext context){
        this.getWiredService(transactionType).doPreWiredMethod(transactionType,nv,context);
        this.defaultWiredService.doPreWiredMethod(transactionType,nv,context);
    }

    @Override
    public void doPostWiredMethod(String transactionType, Nv nv, RuleRunContext context) {
        this.getWiredService(transactionType).doPreWiredMethod(transactionType,nv,context);
        this.defaultWiredService.doPostWiredMethod(transactionType,nv,context);
    }
}
